import Vue from 'vue'
import App from './App'
import GoEasy from './common/goeasy-1.0.11.js'


Vue.prototype.goeasy = GoEasy({
	host: 'hangzhou.goeasy.io',
	appkey: 'BC-e90365d5c2044c80a66c5fb98446bd7e',
	onConnected: function () {
		console.log("GoEasy connect successfully.")
	},
	onDisconnected: function () {
		console.log("GoEasy disconnected.")
	},
	onConnectFailed: function (error) {
		uni.showToast({
			icon: "none",
			title: "websocket连接失败，请检查您的appkey和host配置.",
			duration: 6000
		});
	}
});

//格式化时间
Date.prototype.formatDate = function (fmt) {
	var o = {
		"M+": this.getMonth() + 1,
		"d+": this.getDate(),
		"h+": this.getHours(),
		"m+": this.getMinutes(),
		"s+": this.getSeconds(),
		"q+": Math.floor((this.getMonth() + 3) / 3),
		"S": this.getMilliseconds()
	};
	if (/(y+)/.test(fmt))
		fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	for (var k in o)
		if(o.hasOwnProperty(k)){
			if (new RegExp("(" + k + ")").test(fmt))
				fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
		}
	return fmt;
};


import index from './pages/tabbar/index.vue'
Vue.component('index',index)





import home from './pages/tabbar/home.vue'
Vue.component('home',home)

import cuCustom from './colorui/components/cu-custom.vue'
Vue.component('cu-custom',cuCustom)

import store from './store'
//把vuex定义成全局组件
Vue.prototype.$store = store

import onfire from "./common/onfire/onfire"

const msg = (title="", duration=3000, mask=false, icon='none')=>{
	//统一提示方便全局修改
	if(Boolean(title) === false){
		return;
	}
	uni.showToast({
		title,
		duration,
		mask,
		icon
	});
}

const jump = (item)=>{
	console.log(item)
	switch (item.type){
		// type  1小程序内部指定path  2商品详情跳转  3web跳转  4唤起APP
		case 1:
			uni.navigateTo({
				url:item.path
			})
			break;
		case 2:
		    var data  = {
		    	id:item.path,
		    }
		    uni.navigateTo({
		    	url:'/pages/goods/goods?query='+encodeURIComponent(JSON.stringify(data))
		    })
			break;
			
		case 3:
			uni.navigateTo({
				url:'/pages/web/web?query='+encodeURIComponent(JSON.stringify({url: item.path}))
			})
			break;
		case 4:
			console.warn("跳转APP操作")	
		default:
			break;
	}
}


const prePage = ()=>{
	let pages = getCurrentPages();
	let prePage = pages[pages.length - 2];
	// #ifdef H5
	return prePage;
	// #endif
	return prePage.$vm;
}

Vue.prototype.$api = {msg, prePage, jump};

Vue.prototype.$fire = new onfire()

Vue.config.productionTip = false

App.mpType = 'app'

const app = new Vue({
    ...App,
	store
})
app.$mount()

 



